def isPrime(l):
    if l == 1: return False
    test = True
    k = l - 1
    while k > 1:
        if not l % k:
            test = False
            break
        k -= 1
    return test

t = input()
r = []
for i in range(len(t)):
    for k in range(i + 1,len(t) + 1):
        l = int(t[i:k])
        if isPrime(l):
            r += [l]
print(max(r) if r else 0)